<html>
<head><meta charset="utf-8"><title>const propagation · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html">const propagation</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="164168312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164168312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164168312">(Apr 25 2019 at 13:10)</a>:</h4>
<p>Are there any other tasks that could be worked on while <span class="user-mention" data-user-id="116266">@Santiago Pastorino</span> works on the places refactoring? I'd love to get involved <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="164168582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164168582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164168582">(Apr 25 2019 at 13:14)</a>:</h4>
<p>One thing we have is a const propagator pass that does not propagate constants XD</p>



<a name="164168701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164168701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164168701">(Apr 25 2019 at 13:16)</a>:</h4>
<p>there are a few <code>Place</code> related changes, but they conflict with the current place work, so I'd rather delay that</p>



<a name="164168778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164168778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164168778">(Apr 25 2019 at 13:17)</a>:</h4>
<p>We want to have stable identifiers for e.g. basic blocks (<a href="https://paper.dropbox.com/doc/Topic-MIR-2.0-and-MIR-Optimizations--Ab7LrtY0ql6SAFF3bvSTlMgWAQ-BwHR7kOhxDwL6vuAUoSTQ" target="_blank" title="https://paper.dropbox.com/doc/Topic-MIR-2.0-and-MIR-Optimizations--Ab7LrtY0ql6SAFF3bvSTlMgWAQ-BwHR7kOhxDwL6vuAUoSTQ">https://paper.dropbox.com/doc/Topic-MIR-2.0-and-MIR-Optimizations--Ab7LrtY0ql6SAFF3bvSTlMgWAQ-BwHR7kOhxDwL6vuAUoSTQ</a>) so that removing a block does not invalidate the ids</p>



<a name="164168855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164168855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164168855">(Apr 25 2019 at 13:18)</a>:</h4>
<p>according to the all hands notes we should be comparing notes with cranelift</p>



<a name="164169160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164169160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164169160">(Apr 25 2019 at 13:22)</a>:</h4>
<p>also we'll want some sort of transaction-like mir passes so we can do e.g. inlining, see if that improved anything, if not: just drop the inlined code and keep the old</p>



<a name="164169241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164169241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164169241">(Apr 25 2019 at 13:23)</a>:</h4>
<p>one funky idea is to make <code>MIR</code> independent of rustc, not sure if we can do that in small steps</p>



<a name="164169371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164169371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164169371">(Apr 25 2019 at 13:25)</a>:</h4>
<p>but we can start by pulling all types that do not depend on general compiler types from <code>rustc::mir</code> to <code>rustc_target</code> or similar</p>



<a name="164169379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164169379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164169379">(Apr 25 2019 at 13:25)</a>:</h4>
<blockquote>
<p>One thing we have is a const propagator pass that does not propagate constants XD</p>
</blockquote>
<p>This is interesting. Is there an issue with more details?</p>



<a name="164169541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164169541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164169541">(Apr 25 2019 at 13:27)</a>:</h4>
<p>lol I just found <a href="https://github.com/rust-lang/rust/issues/28238" target="_blank" title="https://github.com/rust-lang/rust/issues/28238">https://github.com/rust-lang/rust/issues/28238</a></p>



<a name="164169548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164169548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164169548">(Apr 25 2019 at 13:27)</a>:</h4>
<p>I guess we can close that</p>



<a name="164169632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164169632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164169632">(Apr 25 2019 at 13:28)</a>:</h4>
<p>hmm.. maybe need to see if my two issues have been fixed</p>



<a name="164169771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164169771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164169771">(Apr 25 2019 at 13:30)</a>:</h4>
<p>so.. unfortunately I think we have no additional info, but I think it shouldn't be too hard to make the const propagator replace <code>Assign</code> rhs with the evaluated value if one has been found (instead of just carrying the values in a shadow datastructure and lint about const eval failures)</p>



<a name="164170065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164170065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164170065">(Apr 25 2019 at 13:34)</a>:</h4>
<p>Ok. I have a vague idea of what const propagation is supposed to do but I haven't looked at the code yet. I'll do that soon and come back to you if I have any questions.</p>



<a name="164392958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164392958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164392958">(Apr 28 2019 at 15:31)</a>:</h4>
<p>Ok. I've read through the <code>const_prop</code> module and I think I've got a handle on how it currently works.</p>



<a name="164392962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164392962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164392962">(Apr 28 2019 at 15:31)</a>:</h4>
<p>I see there's a lot of TODO and FIXME comments that will probably have to be addressed soon</p>



<a name="164393038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164393038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164393038">(Apr 28 2019 at 15:33)</a>:</h4>
<p>Am I correct that in order to get this to actually const prop instead of just lint, I need to add some code <a href="https://github.com/rust-lang/rust/blob/3991285f55a4b7cd92b7ffcdc396a3023076f5cb/src/librustc_mir/transform/const_prop.rs#L566-L569" target="_blank" title="https://github.com/rust-lang/rust/blob/3991285f55a4b7cd92b7ffcdc396a3023076f5cb/src/librustc_mir/transform/const_prop.rs#L566-L569">here-ish</a> to mutate <code>rval</code> to be the <code>value</code> we have?</p>



<a name="164393042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164393042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164393042">(Apr 28 2019 at 15:33)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span></p>



<a name="164393168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164393168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164393168">(Apr 28 2019 at 15:36)</a>:</h4>
<p>yea, you'd need to turn it into a <code>MutVisitor</code> in order to get mut access and then replace the <code>rval</code> with an <code>Rvalue::Use(Operand::Constant(...))</code></p>



<a name="164393181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164393181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164393181">(Apr 28 2019 at 15:36)</a>:</h4>
<p>note that the replacing should not happen with <code>-O0</code>, not even sure if <code>-O1</code> should have it</p>



<a name="164393197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164393197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164393197">(Apr 28 2019 at 15:37)</a>:</h4>
<p>Because it's slow or some other reason?</p>



<a name="164393320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164393320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164393320">(Apr 28 2019 at 15:40)</a>:</h4>
<p>Also, it took a bit of experimentation to get a test case that seemed to actually trigger this codepath in the current const_prop code. Does this look like a reasonable test case? </p>
<div class="codehilite"><pre><span></span><span class="k">const</span><span class="w"> </span><span class="n">A</span>: <span class="p">[</span><span class="kt">i32</span><span class="p">;</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="mi">42</span><span class="p">];</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">A</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span><span class="w"></span>

<span class="w">    </span><span class="n">std</span>::<span class="n">process</span>::<span class="n">exit</span><span class="p">(</span><span class="n">x</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="164393331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164393331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164393331">(Apr 28 2019 at 15:40)</a>:</h4>
<p>(I added the exit call just to make sure <code>x</code> wouldn't be removed as dead code.</p>



<a name="164400452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164400452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164400452">(Apr 28 2019 at 18:33)</a>:</h4>
<p>Slow might be one thing, but that's not really a problem since we're running all of it anyway for diagnostics</p>



<a name="164400457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164400457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164400457">(Apr 28 2019 at 18:33)</a>:</h4>
<p>the problem is that it'll do source code folding so debug information disappears</p>



<a name="164400459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164400459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164400459">(Apr 28 2019 at 18:34)</a>:</h4>
<p>I don't think we have a good setup for this kind of thing yet</p>



<a name="164400509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164400509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164400509">(Apr 28 2019 at 18:34)</a>:</h4>
<p>Shouldn't <code>let x = 1 + 1;</code> already trigger the code you linked?</p>



<a name="164400530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164400530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164400530">(Apr 28 2019 at 18:35)</a>:</h4>
<p>I mean <code>let x = 0u8 - 1;</code> causes a diagnostic via <code>const_prop</code>, so something is happening</p>



<a name="164400539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164400539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164400539">(Apr 28 2019 at 18:35)</a>:</h4>
<p>and I hope <code>let x = (1u8 - 1) - 1;</code> also triggers a diagnostic</p>



<a name="164404630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164404630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164404630">(Apr 28 2019 at 20:08)</a>:</h4>
<p>Oh, perhaps. I thought I tried <code>let x = 1 + 1</code> but didn't see anything in the log output</p>



<a name="164405711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164405711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164405711">(Apr 28 2019 at 20:34)</a>:</h4>
<p>Ah, ok. I think I tried that before I really understood what was going on.</p>



<a name="164405712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164405712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164405712">(Apr 28 2019 at 20:34)</a>:</h4>
<p>That works fine.</p>



<a name="164405717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164405717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164405717">(Apr 28 2019 at 20:34)</a>:</h4>
<p>Now I just need to figure out how to handle <code>ScalarPair</code> lol</p>



<a name="164418171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164418171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164418171">(Apr 29 2019 at 02:03)</a>:</h4>
<p>This seems to have worked <a href="https://github.com/rust-lang/rust/commit/f20b16235409465c84a396321b3d1abbd74e0d3a" target="_blank" title="https://github.com/rust-lang/rust/commit/f20b16235409465c84a396321b3d1abbd74e0d3a">https://github.com/rust-lang/rust/commit/f20b16235409465c84a396321b3d1abbd74e0d3a</a></p>



<a name="164451655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164451655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164451655">(Apr 29 2019 at 13:25)</a>:</h4>
<p><span class="user-mention" data-user-id="125250">@Wesley Wiser</span> if you prefer I can do the const_eval refactoring, this is technical debt built up by me</p>



<a name="164457668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164457668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164457668">(Apr 29 2019 at 14:37)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> No, I don't mind at all unless you really want to do it :)</p>



<a name="164474731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164474731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164474731">(Apr 29 2019 at 18:10)</a>:</h4>
<p>Heh, getting more eyes on that code is great! It's mostly been <span class="user-mention" data-user-id="120791">@RalfJ</span> and I throwing PRs at each other</p>



<a name="164474764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164474764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164474764">(Apr 29 2019 at 18:10)</a>:</h4>
<p>So, all yours!</p>



<a name="164502386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164502386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164502386">(Apr 30 2019 at 01:10)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> Ok, so I think I followed your instructions correctly. That left one instance of <code>self.mir</code>: <a href="https://github.com/rust-lang/rust/blob/00859e3e653973120006aaf3227823062dde1ba7/src/librustc_mir/transform/const_prop.rs#L546" target="_blank" title="https://github.com/rust-lang/rust/blob/00859e3e653973120006aaf3227823062dde1ba7/src/librustc_mir/transform/const_prop.rs#L546">https://github.com/rust-lang/rust/blob/00859e3e653973120006aaf3227823062dde1ba7/src/librustc_mir/transform/const_prop.rs#L546</a></p>
<p>I wasn't sure what to do with that so I tried just removing the need to get the span in the first place. There was really only one line that needed it: <a href="https://github.com/rust-lang/rust/blob/00859e3e653973120006aaf3227823062dde1ba7/src/librustc_mir/transform/const_prop.rs#L257" target="_blank" title="https://github.com/rust-lang/rust/blob/00859e3e653973120006aaf3227823062dde1ba7/src/librustc_mir/transform/const_prop.rs#L257">https://github.com/rust-lang/rust/blob/00859e3e653973120006aaf3227823062dde1ba7/src/librustc_mir/transform/const_prop.rs#L257</a></p>
<p>It seemed to compile even with removing that. Here's the full diff of my changes:<br>
<a href="https://github.com/rust-lang/rust/compare/master...wesleywiser:const_prop_refactoring?expand=1#diff-9e103702275cbef342c2decd3395bf3b#L546" target="_blank" title="https://github.com/rust-lang/rust/compare/master...wesleywiser:const_prop_refactoring?expand=1#diff-9e103702275cbef342c2decd3395bf3b#L546">https://github.com/rust-lang/rust/compare/master...wesleywiser:const_prop_refactoring?expand=1#diff-9e103702275cbef342c2decd3395bf3b#L546</a></p>



<a name="164529327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164529327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164529327">(Apr 30 2019 at 11:03)</a>:</h4>
<p><span class="user-mention" data-user-id="125250">@Wesley Wiser</span> Hmm... I believe I added that to improve diagnostic spans, does <code>./x.py test --stage 1 src/test/ui --bless --test-args const</code> change no stderr files?</p>



<a name="164529346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164529346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164529346">(Apr 30 2019 at 11:03)</a>:</h4>
<p>I'm not sure. I'm getting an ICE earlier in the build</p>



<a name="164529413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164529413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164529413">(Apr 30 2019 at 11:04)</a>:</h4>
<div class="codehilite"><pre><span></span>thread &#39;rustc&#39; panicked at &#39;index out of bounds: the len is 0 but the index is 0&#39;, /Users/wesley/code/rust/rust/src/libcore/slice/mod.rs:2687:10
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::continue_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::panicking::panic_bounds_check
  10: rustc::mir::Mir::return_ty
  11: &lt;rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass&gt;::run_pass
</pre></div>



<a name="164529501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164529501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164529501">(Apr 30 2019 at 11:06)</a>:</h4>
<p>Does this part look right to you? <a href="https://github.com/wesleywiser/rust/blob/94bd101dc679acdf1af16b3b487503711e0466a2/src/librustc_mir/transform/const_prop.rs#L132-L143" target="_blank" title="https://github.com/wesleywiser/rust/blob/94bd101dc679acdf1af16b3b487503711e0466a2/src/librustc_mir/transform/const_prop.rs#L132-L143">https://github.com/wesleywiser/rust/blob/94bd101dc679acdf1af16b3b487503711e0466a2/src/librustc_mir/transform/const_prop.rs#L132-L143</a></p>



<a name="164529628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164529628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164529628">(Apr 30 2019 at 11:09)</a>:</h4>
<p>I assume the issue is that <code>Visitor::super_visit_mir()</code> calls <code>Mir::return_ty()</code>but by this point, <code>mir.local_decls</code> has been replaced with an empty <code>IndexVec</code> and so the return local's index is out of bounds</p>



<a name="164529689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164529689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164529689">(Apr 30 2019 at 11:10)</a>:</h4>
<p>Should I just clone <code>mir.local_decls</code> instead?</p>



<a name="164530515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164530515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164530515">(Apr 30 2019 at 11:27)</a>:</h4>
<p>for now that seems reasonable. Add a <code>FIXME</code> so we'll clean it up</p>



<a name="164530583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164530583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164530583">(Apr 30 2019 at 11:28)</a>:</h4>
<p><code>copy_prop</code> doesn't care about <code>visit_ty</code> and it seems overly expensive to have all visitors fetch those types when most of them don' t use them</p>



<a name="164586872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164586872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164586872">(Apr 30 2019 at 23:43)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> I pushed a PR with just the <code>const_eval</code> changes (<a href="https://github.com/rust-lang/rust/issues/60428" target="_blank" title="https://github.com/rust-lang/rust/issues/60428">#60428</a>). I also fixed the ICE and got a test run of the <code>ui</code> tests. I'm seeing three changes to test output (see <a href="https://github.com/rust-lang/rust/commit/900c618c950cdafeb4c17dcd9cd7aa56e1e231b8" target="_blank" title="https://github.com/rust-lang/rust/commit/900c618c950cdafeb4c17dcd9cd7aa56e1e231b8">this commit</a> for the test diff).</p>



<a name="164605238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164605238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164605238">(May 01 2019 at 07:03)</a>:</h4>
<p>yea, that diff is what I feared</p>



<a name="164605597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164605597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164605597">(May 01 2019 at 07:12)</a>:</h4>
<p>what happens if you use <code>c.span</code> instead of <code>source_info.span</code>?</p>



<a name="164605606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164605606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164605606">(May 01 2019 at 07:12)</a>:</h4>
<p>is that the right span or is it of the const definition site instead of the use site?</p>



<a name="164605626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164605626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164605626">(May 01 2019 at 07:13)</a>:</h4>
<p>otherwise I guess we'll have to change the visitor to pass down the <code>SourceInfo</code> of the <code>Rvalue</code> or <code>Statement</code></p>



<a name="164617839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164617839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164617839">(May 01 2019 at 11:51)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> Oh, that worked pretty well actually</p>



<a name="164617841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164617841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164617841">(May 01 2019 at 11:51)</a>:</h4>
<p>Pushing a diff now...</p>



<a name="164617918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164617918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164617918">(May 01 2019 at 11:53)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/commit/84335207f18542e195fdd8cd412097ca6e7d2496" target="_blank" title="https://github.com/rust-lang/rust/commit/84335207f18542e195fdd8cd412097ca6e7d2496">https://github.com/rust-lang/rust/commit/84335207f18542e195fdd8cd412097ca6e7d2496</a></p>



<a name="164618086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164618086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164618086">(May 01 2019 at 11:56)</a>:</h4>
<p>oh, sweet, that's even an improvement</p>



<a name="164739809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164739809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164739809">(May 02 2019 at 19:55)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> Ok, I think after that PR you r+'d merges, the code is ready to begin actually doing constant propagation. You mentioned that we shouldn't <em>always</em> do this because it will mess up debuginfo. What flag(s) should I gate the optimization under? <code>mir-opt</code>? Regular <code>opt</code>?</p>



<a name="164776871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/164776871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#164776871">(May 03 2019 at 08:33)</a>:</h4>
<p><span class="user-mention" data-user-id="125250">@Wesley Wiser</span> there's some optimization level checking code in the MIR inliner, you can just do the same thing for const prop and not do the copying if the level is not high enough. We should probably start at O3 and can move to lower levels later</p>



<a name="165064206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165064206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165064206">(May 07 2019 at 11:57)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> </p>
<blockquote>
<p>create a helper function for obtaining an Operand from a ty::Const (or maybe even from a Scalar + Ty, although in the future we'll probably need the ty::Const, too)</p>
</blockquote>
<p>Do you mean add a helper function to <code>OpTy</code> (<code>OpTy</code> is aliased as <code>Const</code> on line 82)?</p>



<a name="165064220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165064220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165064220">(May 07 2019 at 11:57)</a>:</h4>
<p>oh</p>



<a name="165064223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165064223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165064223">(May 07 2019 at 11:57)</a>:</h4>
<p>right</p>



<a name="165064274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165064274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165064274">(May 07 2019 at 11:58)</a>:</h4>
<p>wait</p>



<a name="165064280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165064280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165064280">(May 07 2019 at 11:58)</a>:</h4>
<p>no I think I meant <code>ty::Const</code>, but let me check</p>



<a name="165064436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165064436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165064436">(May 07 2019 at 12:00)</a>:</h4>
<p>in <a href="https://github.com/rust-lang/rust/pull/60597/files#diff-9e103702275cbef342c2decd3395bf3bR506" target="_blank" title="https://github.com/rust-lang/rust/pull/60597/files#diff-9e103702275cbef342c2decd3395bf3bR506">https://github.com/rust-lang/rust/pull/60597/files#diff-9e103702275cbef342c2decd3395bf3bR506</a> you need an <code>Operand::Constant</code> to put into the <code>Rvalue::Use</code> and in <a href="https://github.com/rust-lang/rust/pull/60597/files#diff-9e103702275cbef342c2decd3395bf3bR527" target="_blank" title="https://github.com/rust-lang/rust/pull/60597/files#diff-9e103702275cbef342c2decd3395bf3bR527">https://github.com/rust-lang/rust/pull/60597/files#diff-9e103702275cbef342c2decd3395bf3bR527</a> you need <code>Operand::Constant</code> for the <code>Vec</code> of the tuple elements</p>



<a name="165064455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165064455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165064455">(May 07 2019 at 12:00)</a>:</h4>
<p>so the helper should directly produce <code>Operand</code> (which would always be <code>Operand::Const</code>), in order to reduce duplication between the sites going from a <code>Scalar</code> + <code>Ty</code> to <code>Operand</code></p>



<a name="165064562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165064562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165064562">(May 07 2019 at 12:02)</a>:</h4>
<p>Oh, ok. But the helper function goes from <code>rustc_mir::interpret::Scalar</code> to <code>Operand</code> right?</p>



<a name="165064571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165064571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165064571">(May 07 2019 at 12:02)</a>:</h4>
<p>I don't have a <code>Const</code> to turn into an <code>Operand</code></p>



<a name="165065160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165065160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165065160">(May 07 2019 at 12:12)</a>:</h4>
<p>heh, right, my comment about <code>Const</code> was about <code>ty::Const</code>, which you'd have to create</p>



<a name="165065167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165065167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165065167">(May 07 2019 at 12:12)</a>:</h4>
<p>but that's unnecessary right now</p>



<a name="165065174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165065174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165065174">(May 07 2019 at 12:12)</a>:</h4>
<p>might become necessary in the future</p>



<a name="165065181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165065181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165065181">(May 07 2019 at 12:12)</a>:</h4>
<p>but then we can split the helper into two</p>



<a name="165065238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165065238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165065238">(May 07 2019 at 12:13)</a>:</h4>
<p>Ok, sounds good. I'll push up the changes in a minute</p>



<a name="165149271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165149271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165149271">(May 08 2019 at 10:00)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> Did you still want to do a perf run of <a href="https://github.com/rust-lang/rust/issues/60597" target="_blank" title="https://github.com/rust-lang/rust/issues/60597">#60597</a>?</p>



<a name="165150161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165150161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165150161">(May 08 2019 at 10:17)</a>:</h4>
<p>no, you're right, it's useless right now</p>



<a name="165150166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165150166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165150166">(May 08 2019 at 10:17)</a>:</h4>
<p>we'll do that when we lower the O level</p>



<a name="165150459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165150459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165150459">(May 08 2019 at 10:22)</a>:</h4>
<p>Ok</p>



<a name="165150474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165150474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165150474">(May 08 2019 at 10:22)</a>:</h4>
<p>If you want, I can push a temporary commit to remove the o3 check just for the perf run</p>



<a name="165151222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165151222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165151222">(May 08 2019 at 10:37)</a>:</h4>
<p>nah, we'll do that in a separate PR</p>



<a name="165151234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165151234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165151234">(May 08 2019 at 10:37)</a>:</h4>
<p>I mean... we could experiment with moving this to <code>O1</code> since most of the work is being done <em>anyway</em></p>



<a name="165151343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165151343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165151343">(May 08 2019 at 10:39)</a>:</h4>
<p>True</p>



<a name="165151427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165151427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165151427">(May 08 2019 at 10:40)</a>:</h4>
<p>Let me push a commit just so we can see what the performance impact is and then we can decide whether to put it in <code>O1</code> or <code>O3</code></p>



<a name="165151437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165151437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165151437">(May 08 2019 at 10:40)</a>:</h4>
<p>sgtm</p>



<a name="165151455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165151455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165151455">(May 08 2019 at 10:41)</a>:</h4>
<p>(if you're alright with the PR taking longer to get merged, otherwise we can do a PR with just the move to O1)</p>



<a name="165151655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165151655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165151655">(May 08 2019 at 10:44)</a>:</h4>
<p>It's fine with me either way. eddyb still needs to review and if that happens soon, we can do the move to O1 in another PR as you said</p>



<a name="165151666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165151666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165151666">(May 08 2019 at 10:44)</a>:</h4>
<p>heh ping <span class="user-mention" data-user-id="119009">@eddyb</span></p>



<a name="165264619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165264619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165264619">(May 09 2019 at 15:48)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span>  Do you have any thoughts about what optimization level this should be gated on? The performance results are in <a href="https://github.com/rust-lang/rust/pull/60597#issuecomment-490479633" target="_blank" title="https://github.com/rust-lang/rust/pull/60597#issuecomment-490479633">this comment</a>.</p>



<a name="165265062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165265062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165265062">(May 09 2019 at 15:52)</a>:</h4>
<p>Yea, imo we should go with O1</p>



<a name="165265099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165265099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165265099">(May 09 2019 at 15:53)</a>:</h4>
<p>uncontroversial would be O2, so we could start there though</p>



<a name="165265142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165265142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165265142">(May 09 2019 at 15:53)</a>:</h4>
<p>O1 is also what I was thinking</p>



<a name="165265156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165265156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165265156">(May 09 2019 at 15:53)</a>:</h4>
<p>I'll make that change tonight and fix any test fallout</p>



<a name="165329866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165329866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165329866">(May 10 2019 at 11:56)</a>:</h4>
<p>Are the changes to to codegen tests concerning? When <code>-O</code> is enabled, they seem to optimize to the same thing.</p>
<p><a href="https://gist.github.com/wesleywiser/2af3fd2ef1fec4df3ba75786098ef3b5/revisions" target="_blank" title="https://gist.github.com/wesleywiser/2af3fd2ef1fec4df3ba75786098ef3b5/revisions">Diff between mir-opt-level=0 and mir-opt-level=1</a></p>



<a name="165334600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165334600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165334600">(May 10 2019 at 13:11)</a>:</h4>
<p>oh <span aria-label="confused" class="emoji emoji-1f615" role="img" title="confused">:confused:</span> That's not good</p>



<a name="165334608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165334608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165334608">(May 10 2019 at 13:11)</a>:</h4>
<p>llvm will clean it up, but still</p>



<a name="165334619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165334619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165334619">(May 10 2019 at 13:11)</a>:</h4>
<p>I guess our constant -&gt; llvm lowering step isn't very good</p>



<a name="165334646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165334646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165334646">(May 10 2019 at 13:12)</a>:</h4>
<p>that may explain why the unoptimized case regressed in the perf run</p>



<a name="165334896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165334896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165334896">(May 10 2019 at 13:15)</a>:</h4>
<p>I can kinda see how that would happen... Maybe we should try to read a <code>ScalarPair</code> out of a constant before converting it to llvm</p>



<a name="165335001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165335001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165335001">(May 10 2019 at 13:17)</a>:</h4>
<p>Basically if we have <code>TyLayout</code> with<code>Abi::ScalarPair</code>, but <code>ConstValue::ByRef</code>, we'd read a pair from the <code>Allocation</code>. I think I tried to setup some code for that a while back, but never got around to actually ripping it out of <code>InterpCtx</code> and moving it to <code>Allocation</code></p>



<a name="165335814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165335814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165335814">(May 10 2019 at 13:27)</a>:</h4>
<p>I guess the other thing would be to improve the const propagation a bit more. As it is, you end up with code like:</p>
<div class="codehilite"><pre><span></span>      _2 = (const 2u32, const false);
      assert(!move (_2.1: bool), &quot;attempt to add with overflow&quot;) -&gt; bb1;
</pre></div>


<p>where <code>!move (_2.1: bool)</code> should just become <code>const false</code> and then simplify branches should take care of it from there</p>



<a name="165335937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165335937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165335937">(May 10 2019 at 13:29)</a>:</h4>
<p>yea, there's some code that will emit the <code>attempt to add with overflow</code> diagnostic from assertions know to trigger. That same place could overwrite the <code>_2.1</code> with the propagated value. I don't know if we should do that in the same PR though</p>



<a name="165335965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165335965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165335965">(May 10 2019 at 13:29)</a>:</h4>
<p>the same thing goes for other branches with know-constant branching (which are turned into <code>goto</code> once the constant is promoted into the terminator)</p>



<a name="165336215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336215">(May 10 2019 at 13:32)</a>:</h4>
<p>Sure, that could be done in another PR. I guess we should gate this under O2 then?</p>



<a name="165336222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336222">(May 10 2019 at 13:32)</a>:</h4>
<p>I think part of the issue is this <a href="https://github.com/rust-lang/rust/blob/0ac53da03dad79655e2f3e65a58f94a2f3314d5f/src/librustc_mir/transform/const_prop.rs#L527" target="_blank" title="https://github.com/rust-lang/rust/blob/0ac53da03dad79655e2f3e65a58f94a2f3314d5f/src/librustc_mir/transform/const_prop.rs#L527">https://github.com/rust-lang/rust/blob/0ac53da03dad79655e2f3e65a58f94a2f3314d5f/src/librustc_mir/transform/const_prop.rs#L527</a></p>



<a name="165336277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336277">(May 10 2019 at 13:33)</a>:</h4>
<p>Once a Local is determined to be propagatable, shouldn't uses of it also be propagatable?</p>



<a name="165336284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336284">(May 10 2019 at 13:33)</a>:</h4>
<p>I don't think that currently happens but I might be wrong</p>



<a name="165336422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336422">(May 10 2019 at 13:35)</a>:</h4>
<p>ah, no that's a different issue</p>



<a name="165336476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336476">(May 10 2019 at 13:36)</a>:</h4>
<p>we need dataflow in order to know what we can actually promote</p>



<a name="165336482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336482">(May 10 2019 at 13:36)</a>:</h4>
<p>but at that point we should be merging const prop and copy prop I guess</p>



<a name="165336485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336485">(May 10 2019 at 13:36)</a>:</h4>
<p>Ah ok</p>



<a name="165336537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336537">(May 10 2019 at 13:37)</a>:</h4>
<p>I'm surprised <code>move (_2.1: bool)</code> isn't already const propagated</p>



<a name="165336543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336543">(May 10 2019 at 13:37)</a>:</h4>
<p>Since it's just reading a constant</p>



<a name="165336560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336560">(May 10 2019 at 13:37)</a>:</h4>
<p>oh it is, but your code only writes propagations to locals</p>



<a name="165336563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336563">(May 10 2019 at 13:37)</a>:</h4>
<p>this is a propagation into an <code>Operand</code></p>



<a name="165336628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336628">(May 10 2019 at 13:38)</a>:</h4>
<p>Oh gotcha</p>



<a name="165336632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336632">(May 10 2019 at 13:38)</a>:</h4>
<p>right now as the PR stands there is no propagation into terminators</p>



<a name="165336638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336638">(May 10 2019 at 13:38)</a>:</h4>
<p>just into assignment statements</p>



<a name="165336639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336639">(May 10 2019 at 13:38)</a>:</h4>
<p>Is that still in scope for <code>ConstProp</code>?</p>



<a name="165336643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336643">(May 10 2019 at 13:38)</a>:</h4>
<p>yea</p>



<a name="165336670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336670">(May 10 2019 at 13:39)</a>:</h4>
<p>that's what I meant with "not in this PR"</p>



<a name="165336676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336676">(May 10 2019 at 13:39)</a>:</h4>
<p><span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span></p>



<a name="165336698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336698">(May 10 2019 at 13:39)</a>:</h4>
<p>Do you want me to switch this back to <code>O2</code> then?</p>



<a name="165336701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336701">(May 10 2019 at 13:39)</a>:</h4>
<p>yea, I guess go back to O2 and I'll try to figure out the better llvm codegen story</p>



<a name="165336702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336702">(May 10 2019 at 13:39)</a>:</h4>
<p>So there's no regressions</p>



<a name="165336713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336713">(May 10 2019 at 13:39)</a>:</h4>
<p>Alright</p>



<a name="165336718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336718">(May 10 2019 at 13:39)</a>:</h4>
<p>Thanks!</p>



<a name="165336729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336729">(May 10 2019 at 13:39)</a>:</h4>
<p>I don't remember what the problems were, maybe they have become obsolete</p>



<a name="165336797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165336797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165336797">(May 10 2019 at 13:40)</a>:</h4>
<p>That would be nice</p>



<a name="165437187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165437187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165437187">(May 12 2019 at 00:30)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> <code>ConstProp</code> into terminators helps a lot <a href="https://github.com/rust-lang/rust/pull/60745#issuecomment-491530334" target="_blank" title="https://github.com/rust-lang/rust/pull/60745#issuecomment-491530334">https://github.com/rust-lang/rust/pull/60745#issuecomment-491530334</a></p>



<a name="165456927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165456927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165456927">(May 12 2019 at 09:32)</a>:</h4>
<p>wow, that's awesome</p>



<a name="165456977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165456977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165456977">(May 12 2019 at 09:33)</a>:</h4>
<p>I guess it makes sense, because subsequent passes can eliminate a lot of basic blocks this way</p>



<a name="165493465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165493465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165493465">(May 13 2019 at 02:48)</a>:</h4>
<p>It looks like it's improved the codegen quite a bit from those results I posted the other day. The code generated is still different but it may actually be reasonable now.</p>



<a name="165493606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165493606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165493606">(May 13 2019 at 02:51)</a>:</h4>
<p>Latest results: <a href="https://gist.github.com/wesleywiser/548f58348bd2d24fcf7e5aa1603f53c6/revisions" target="_blank" title="https://gist.github.com/wesleywiser/548f58348bd2d24fcf7e5aa1603f53c6/revisions">https://gist.github.com/wesleywiser/548f58348bd2d24fcf7e5aa1603f53c6/revisions</a></p>



<a name="165493664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165493664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165493664">(May 13 2019 at 02:53)</a>:</h4>
<p>There's still some dead variables in there but removing the panic checks seem like a win to me. I don't know a lot about LLVM though.</p>



<a name="165507638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165507638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165507638">(May 13 2019 at 08:18)</a>:</h4>
<p>wait this is for release mode!?</p>



<a name="165516822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165516822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165516822">(May 13 2019 at 10:47)</a>:</h4>
<p>No, this is <code>-Copt-level=0</code></p>



<a name="165517041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165517041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165517041">(May 13 2019 at 10:51)</a>:</h4>
<p>With <code>-Copt-level=3</code>, there's no change in generated IR. LLVM optimizes everything to</p>
<div class="codehilite"><pre><span></span><span class="c">; Function Attrs: norecurse nounwind readnone uwtable</span>
<span class="k">define</span> <span class="k">i32</span> <span class="vg">@nothing</span><span class="p">()</span> <span class="k">unnamed_addr</span> <span class="vg">#0</span> <span class="p">{</span>
<span class="nl">start:</span>
  <span class="k">ret</span> <span class="k">i32</span> <span class="m">4</span>
<span class="p">}</span>
</pre></div>



<a name="165517989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165517989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165517989">(May 13 2019 at 11:09)</a>:</h4>
<p>ah ok, that makes sense</p>



<a name="165583175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165583175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165583175">(May 14 2019 at 00:53)</a>:</h4>
<p>still probably makes LLVM faster at doing it's thing</p>



<a name="165610837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165610837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165610837">(May 14 2019 at 10:34)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="119009">@eddyb</span>, what did you mean with this feedback? <a href="https://github.com/rust-lang/rust/pull/60597/files/ba7b8312929f39b890f437063f2eec27984fdd19#r283381539" target="_blank" title="https://github.com/rust-lang/rust/pull/60597/files/ba7b8312929f39b890f437063f2eec27984fdd19#r283381539">https://github.com/rust-lang/rust/pull/60597/files/ba7b8312929f39b890f437063f2eec27984fdd19#r283381539</a></p>



<a name="165610855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165610855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165610855">(May 14 2019 at 10:35)</a>:</h4>
<p>what I mean is that you should be able to take <code>value: Const&lt;'tcx&gt;</code> and turn it into <code>ty::Const</code></p>



<a name="165610863"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165610863" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165610863">(May 14 2019 at 10:35)</a>:</h4>
<p>the same way miri does when you do <code>tcx.const_eval</code> or w/e</p>



<a name="165610917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165610917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165610917">(May 14 2019 at 10:36)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> knows this better than me</p>



<a name="165610918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165610918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165610918">(May 14 2019 at 10:36)</a>:</h4>
<p>We've already done <code>const-eval</code> at this point and got a <code>OpTy</code></p>



<a name="165610925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165610925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165610925">(May 14 2019 at 10:36)</a>:</h4>
<p>but we need to turn the <code>OpTy</code> into an <code>Rvalue</code></p>



<a name="165610947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165610947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165610947">(May 14 2019 at 10:37)</a>:</h4>
<p>(there's a <code>type Const = OpTy;</code> statement much earlier in this file)</p>



<a name="165611169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165611169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165611169">(May 14 2019 at 10:42)</a>:</h4>
<p>The specific branch you commented on handles the case where <code>OpTy</code> is a <code>Immediate::ScalarPair</code> which happens when evaluating checked math.</p>



<a name="165611214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165611214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165611214">(May 14 2019 at 10:43)</a>:</h4>
<p>This test case triggers that code path: <a href="https://github.com/rust-lang/rust/pull/60597/files/ba7b8312929f39b890f437063f2eec27984fdd19#diff-441c8694f396fc233e098b0ed39d59a1" target="_blank" title="https://github.com/rust-lang/rust/pull/60597/files/ba7b8312929f39b890f437063f2eec27984fdd19#diff-441c8694f396fc233e098b0ed39d59a1">https://github.com/rust-lang/rust/pull/60597/files/ba7b8312929f39b890f437063f2eec27984fdd19#diff-441c8694f396fc233e098b0ed39d59a1</a></p>



<a name="165611285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165611285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165611285">(May 14 2019 at 10:44)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> ^ <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="165611310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165611310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165611310">(May 14 2019 at 10:45)</a>:</h4>
<p>my point is that it doesn't matter what kind of <code>OpTy</code> this is</p>



<a name="165611314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165611314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165611314">(May 14 2019 at 10:45)</a>:</h4>
<p>it can be uniformly converted into a <code>ty::Const</code></p>



<a name="165611317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165611317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165611317">(May 14 2019 at 10:45)</a>:</h4>
<p>and it should be going through <em>that</em> pathway</p>



<a name="165611366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165611366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165611366">(May 14 2019 at 10:46)</a>:</h4>
<p>which probably does even more validity checks</p>



<a name="165611393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165611393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165611393">(May 14 2019 at 10:47)</a>:</h4>
<p>I don't think you're using <em>literally</em> <code>tcx.const_eval(...)</code>, but rather using miri directly</p>



<a name="165611408"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165611408" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165611408">(May 14 2019 at 10:47)</a>:</h4>
<p><code>tcx.const_eval(...)</code> <em>in particular</em> has a conversion step, from miri to <code>ty::Const</code></p>



<a name="165611491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165611491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165611491">(May 14 2019 at 10:49)</a>:</h4>
<p>Ok</p>



<a name="165611495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165611495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165611495">(May 14 2019 at 10:49)</a>:</h4>
<p>Looks like we use <code>eval_promoted</code> <a href="https://github.com/rust-lang/rust/blob/ba7b8312929f39b890f437063f2eec27984fdd19/src/librustc_mir/transform/const_prop.rs#L328" target="_blank" title="https://github.com/rust-lang/rust/blob/ba7b8312929f39b890f437063f2eec27984fdd19/src/librustc_mir/transform/const_prop.rs#L328">https://github.com/rust-lang/rust/blob/ba7b8312929f39b890f437063f2eec27984fdd19/src/librustc_mir/transform/const_prop.rs#L328</a></p>



<a name="165612232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165612232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165612232">(May 14 2019 at 11:01)</a>:</h4>
<p>The problem is code like binary op evaluation: <a href="https://github.com/rust-lang/rust/blob/ba7b8312929f39b890f437063f2eec27984fdd19/src/librustc_mir/transform/const_prop.rs#L479" target="_blank" title="https://github.com/rust-lang/rust/blob/ba7b8312929f39b890f437063f2eec27984fdd19/src/librustc_mir/transform/const_prop.rs#L479">https://github.com/rust-lang/rust/blob/ba7b8312929f39b890f437063f2eec27984fdd19/src/librustc_mir/transform/const_prop.rs#L479</a></p>



<a name="165612302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165612302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165612302">(May 14 2019 at 11:02)</a>:</h4>
<p>for checked bin ops you get a pair of the result + the overflow bit</p>



<a name="165612835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165612835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165612835">(May 14 2019 at 11:11)</a>:</h4>
<p>I don't see any functions for converting an <code>MPlaceTy</code> to a <code>ty::Const</code></p>



<a name="165613392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165613392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165613392">(May 14 2019 at 11:19)</a>:</h4>
<p>mplace-&gt;const is private: <a href="https://github.com/rust-lang/rust/blob/13fde05b12c28e1ed66bd13fdf1ea392f166b811/src/librustc_mir/const_eval.rs#L65" target="_blank" title="https://github.com/rust-lang/rust/blob/13fde05b12c28e1ed66bd13fdf1ea392f166b811/src/librustc_mir/const_eval.rs#L65">https://github.com/rust-lang/rust/blob/13fde05b12c28e1ed66bd13fdf1ea392f166b811/src/librustc_mir/const_eval.rs#L65</a></p>



<a name="165613396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165613396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165613396">(May 14 2019 at 11:19)</a>:</h4>
<p>and I don't think we should use it</p>



<a name="165613452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165613452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165613452">(May 14 2019 at 11:20)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> converting to a <code>ty::Const</code> would be extra effort, what's the problem you see with the <code>mir::Aggregate</code>?</p>



<a name="165613470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165613470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165613470">(May 14 2019 at 11:20)</a>:</h4>
<p>I think the current implementation is hacky</p>



<a name="165613480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165613480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165613480">(May 14 2019 at 11:20)</a>:</h4>
<p>and we should be doing something that's both more general <em>and</em> validity-checked</p>



<a name="165613510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165613510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165613510">(May 14 2019 at 11:21)</a>:</h4>
<p>hm. that will require useless addtional miri allocations (useless because they will often not end up in llvm)</p>



<a name="165613615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165613615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165613615">(May 14 2019 at 11:22)</a>:</h4>
<p>because <code>ty::Const</code> can't represent arbitrary pairs?</p>



<a name="165613618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165613618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165613618">(May 14 2019 at 11:22)</a>:</h4>
<p>what was the reasoning behind that?</p>



<a name="165613679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165613679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165613679">(May 14 2019 at 11:23)</a>:</h4>
<p>can you at least move the scalar -&gt; <code>ty::Const</code> logic to miri, share it with <code>tcx.const_eval(...)</code> and have it do validity checks?</p>



<a name="165613682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165613682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165613682">(May 14 2019 at 11:23)</a>:</h4>
<p>the reasoning was that we didn't really use that feature and most uses just want slice information</p>



<a name="165613691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165613691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165613691">(May 14 2019 at 11:23)</a>:</h4>
<p>and then we can keep the <code>ty::Tuple</code> hack with a comment that it might be better to just represent the scalar pair case in <code>ty::Const</code></p>



<a name="165613797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165613797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165613797">(May 14 2019 at 11:25)</a>:</h4>
<p>ah, now I understand what issue you have with this.</p>



<a name="165613905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165613905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165613905">(May 14 2019 at 11:27)</a>:</h4>
<p>Ok, so we can expose <a href="https://github.com/rust-lang/rust/blob/13fde05b12c28e1ed66bd13fdf1ea392f166b811/src/librustc_mir/const_eval.rs#L85" target="_blank" title="https://github.com/rust-lang/rust/blob/13fde05b12c28e1ed66bd13fdf1ea392f166b811/src/librustc_mir/const_eval.rs#L85">https://github.com/rust-lang/rust/blob/13fde05b12c28e1ed66bd13fdf1ea392f166b811/src/librustc_mir/const_eval.rs#L85</a> via a wrapper that also does <a href="https://github.com/rust-lang/rust/blob/13fde05b12c28e1ed66bd13fdf1ea392f166b811/src/librustc_mir/const_eval.rs#L493" target="_blank" title="https://github.com/rust-lang/rust/blob/13fde05b12c28e1ed66bd13fdf1ea392f166b811/src/librustc_mir/const_eval.rs#L493">https://github.com/rust-lang/rust/blob/13fde05b12c28e1ed66bd13fdf1ea392f166b811/src/librustc_mir/const_eval.rs#L493</a> first</p>



<a name="165614057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614057">(May 14 2019 at 11:30)</a>:</h4>
<p>yeah that makes sense</p>



<a name="165614084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614084">(May 14 2019 at 11:30)</a>:</h4>
<p>I'm not sure how one would get an invalid constant here, we should probably just ICE when that happens. We start out with validated constants and are const propagating the various operations via miri code. What do you think about doing validation directly on the operations just like miri the tool does it and then don't do the propagation if validation fails</p>



<a name="165614090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614090">(May 14 2019 at 11:30)</a>:</h4>
<p>sure</p>



<a name="165614112"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614112" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614112">(May 14 2019 at 11:31)</a>:</h4>
<p>basically the const prop optimizations can then be used more wildly, because they will be rolled back if anything looks awry</p>



<a name="165614296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614296">(May 14 2019 at 11:35)</a>:</h4>
<p><span class="user-mention" data-user-id="125250">@Wesley Wiser</span> So, as a first step we'd need a test ensuring that <code>&amp;1 as *const i32 as usize</code> does not result in a <code>ty::Const</code> of type <code>usize</code> with value <code>Scalar(Ptr(AllocId(some_number), 0))</code></p>



<a name="165614302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614302">(May 14 2019 at 11:35)</a>:</h4>
<p>(after optimizations)</p>



<a name="165614306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614306">(May 14 2019 at 11:35)</a>:</h4>
<p>that will probably fail right now</p>



<a name="165614496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614496">(May 14 2019 at 11:39)</a>:</h4>
<p>Then you can add a call to <code>ecx.validate_operand(op, vec![], Some(&amp;mut RefTracking::new(op)), /*const_mode*/true)?;</code> to the conversion method.</p>



<a name="165614519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614519">(May 14 2019 at 11:39)</a>:</h4>
<p>For good measure throw the conversion method onto <code>InterpCx</code>, since I believe it needs nothing from the const propagator</p>



<a name="165614581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614581">(May 14 2019 at 11:40)</a>:</h4>
<p>Alright</p>



<a name="165614709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614709">(May 14 2019 at 11:43)</a>:</h4>
<p>So this:</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="mi">1</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">usize</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">read</span><span class="p">(</span><span class="n">x</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>results in </p>
<div class="codehilite"><pre><span></span>        _3 = &amp;(promoted[0]: i32);
        _2 = move _3 as *const i32 (Misc);
        _1 = move _2 as usize (Misc);
        _4 = const read(move _1) -&gt; bb1;
</pre></div>



<a name="165614714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614714">(May 14 2019 at 11:43)</a>:</h4>
<p>(Before and after my changes)</p>



<a name="165614717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614717">(May 14 2019 at 11:43)</a>:</h4>
<p>Which seems correct to me</p>



<a name="165614745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165614745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165614745">(May 14 2019 at 11:44)</a>:</h4>
<p>Right?</p>



<a name="165615042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165615042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165615042">(May 14 2019 at 11:48)</a>:</h4>
<p>hmm. I guess we haven't implemented <code>&amp;</code></p>



<a name="165615061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165615061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165615061">(May 14 2019 at 11:49)</a>:</h4>
<p>use an intermediate <code>const FOO: &amp;i32 = &1; let x = FOO as *const i32 as usize;</code></p>



<a name="165615190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165615190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165615190">(May 14 2019 at 11:51)</a>:</h4>
<p>I don't see any difference there either:</p>
<div class="codehilite"><pre><span></span>        _2 = const Unevaluated(DefId(0/0:5 ~ test[317d]::main[0]::FOO[0]), []) : &amp;i32 as *const i32 (Misc); // bb0[1]: scope 0 at test.rs:6:13: 6:16
                                         // ty::Const
                                         // + ty: &amp;i32
                                         // + val: Unevaluated(DefId(0/0:5 ~ test[317d]::main[0]::FOO[0]), [])
                                         // mir::Constant
                                         // + span: test.rs:6:13: 6:16
                                         // + ty: &amp;i32
                                         // + literal: Const { ty: &amp;i32, val: Unevaluated(DefId(0/0:5 ~ test[317d]::main[0]::FOO[0]), []) }
        _1 = move _2 as usize (Misc);
        StorageDead(_2);
        _3 = const read(move _1) -&gt; bb1;
</pre></div>



<a name="165615248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165615248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165615248">(May 14 2019 at 11:52)</a>:</h4>
<p>(Guessing that you're correct and <code>&amp;</code> isn't implemented leading to the <code>Unevaluated</code> stuff)</p>



<a name="165615281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165615281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165615281">(May 14 2019 at 11:53)</a>:</h4>
<p>No, <code>Unevaluated</code> happens because we're early in the optimization pipeline</p>



<a name="165615286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165615286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165615286">(May 14 2019 at 11:53)</a>:</h4>
<p><code>&amp;</code> is not implemented for const prop</p>



<a name="165615338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165615338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165615338">(May 14 2019 at 11:54)</a>:</h4>
<p>Oh, ok</p>



<a name="165617051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165617051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165617051">(May 14 2019 at 12:23)</a>:</h4>
<p>hm, oh sorry I forgot about this thread. Let's see why this isn't getting optimized</p>



<a name="165617375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165617375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165617375">(May 14 2019 at 12:27)</a>:</h4>
<p>I don't get it. All the parts are there. are you testing this with your PR and the appropriate optimization levels?</p>



<a name="165617664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165617664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165617664">(May 14 2019 at 12:31)</a>:</h4>
<p>Here's what I'm doing:</p>
<div class="codehilite"><pre><span></span>rustc +stage1-2 --emit mir -C overflow-checks=on -Copt-level=0 -Z mir-opt-level=3 -Z dump-mir=&quot;&quot; test.rs
</pre></div>



<a name="165617687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165617687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165617687">(May 14 2019 at 12:31)</a>:</h4>
<div class="codehilite"><pre><span></span>narada:rust wesley$ cat test.rs
<span class="c1">#[inline(never)]</span>
fn read&lt;T&gt;<span class="o">(</span>_: T<span class="o">)</span> <span class="o">{</span> <span class="o">}</span>

fn main<span class="o">()</span> <span class="o">{</span>
    const FOO: <span class="p">&amp;</span><span class="nv">i32</span> <span class="o">=</span> <span class="p">&amp;</span><span class="m">1</span><span class="p">;</span>
    <span class="nb">let</span> <span class="nv">x</span> <span class="o">=</span> FOO as *const i32 as usize<span class="p">;</span>
    read<span class="o">(</span>x<span class="o">)</span><span class="p">;</span>
<span class="o">}</span>
</pre></div>



<a name="165617752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165617752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165617752">(May 14 2019 at 12:32)</a>:</h4>
<p>very weird. I'm assuming <code>1i32 as u32</code> works though?</p>



<a name="165617780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165617780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165617780">(May 14 2019 at 12:32)</a>:</h4>
<div class="codehilite"><pre><span></span>narada:rust wesley$ cat mir_dump/rustc.main.003-018.ConstProp.after.mir
// MIR for `main`
// source = MirSource { instance: Item(DefId(0/0:4 ~ test[317d]::main[0])), promoted: None }
// pass_name = ConstProp
// disambiguator = after

fn  main() -&gt; () {
    let mut _0: ();                      // return place in scope 0 at test.rs:4:11: 4:11
    let mut _2: *const i32;              // in scope 0 at test.rs:6:13: 6:30
    let mut _3: &amp;i32;                    // in scope 0 at test.rs:6:13: 6:16
    let mut _4: &amp;i32;                    // in scope 0 at test.rs:6:13: 6:16
    let mut _5: ();                      // in scope 0 at test.rs:7:5: 7:12
    let mut _6: usize;                   // in scope 0 at test.rs:7:10: 7:11
    scope 1 {
        let _1: usize;                   // &quot;x&quot; in scope 1 at test.rs:6:9: 6:10
    }
    scope 2 {
    }

    bb0: {
        StorageLive(_1);                 // bb0[0]: scope 0 at test.rs:6:9: 6:10
        StorageLive(_2);                 // bb0[1]: scope 0 at test.rs:6:13: 6:30
        StorageLive(_3);                 // bb0[2]: scope 0 at test.rs:6:13: 6:16
        StorageLive(_4);                 // bb0[3]: scope 0 at test.rs:6:13: 6:16
        _4 = const Unevaluated(DefId(0/0:5 ~ test[317d]::main[0]::FOO[0]), []) : &amp;i32; // bb0[4]: scope 0 at test.rs:6:13: 6:16
                                         // ty::Const
                                         // + ty: &amp;i32
                                         // + val: Unevaluated(DefId(0/0:5 ~ test[317d]::main[0]::FOO[0]), [])
                                         // mir::Constant
                                         // + span: test.rs:6:13: 6:16
                                         // + ty: &amp;i32
                                         // + literal: Const { ty: &amp;i32, val: Unevaluated(DefId(0/0:5 ~ test[317d]::main[0]::FOO[0]), []) }
        _3 = _4;                         // bb0[5]: scope 0 at test.rs:6:13: 6:16
        _2 = move _3 as *const i32 (Misc); // bb0[6]: scope 0 at test.rs:6:13: 6:16
        StorageDead(_3);                 // bb0[7]: scope 0 at test.rs:6:15: 6:16
        _1 = move _2 as usize (Misc);    // bb0[8]: scope 0 at test.rs:6:13: 6:39
        StorageDead(_2);                 // bb0[9]: scope 0 at test.rs:6:38: 6:39
        StorageDead(_4);                 // bb0[10]: scope 0 at test.rs:6:39: 6:40
        StorageLive(_6);                 // bb0[11]: scope 2 at test.rs:7:10: 7:11
        _6 = _1;                         // bb0[12]: scope 2 at test.rs:7:10: 7:11
        _5 = const read(move _6) -&gt; bb1; // bb0[13]: scope 2 at test.rs:7:5: 7:12
                                         // ty::Const
                                         // + ty: fn(usize) {read::&lt;usize&gt;}
                                         // + val: Scalar(Bits { size: 0, bits: 0 })
                                         // mir::Constant
                                         // + span: test.rs:7:5: 7:9
                                         // + ty: fn(usize) {read::&lt;usize&gt;}
                                         // + literal: Const { ty: fn(usize) {read::&lt;usize&gt;}, val: Scalar(Bits { size: 0, bits: 0 }) }
    }

    bb1: {
        StorageDead(_6);                 // bb1[0]: scope 2 at test.rs:7:11: 7:12
        _0 = ();                         // bb1[1]: scope 0 at test.rs:4:11: 8:2
        StorageDead(_1);                 // bb1[2]: scope 0 at test.rs:8:1: 8:2
        return;                          // bb1[3]: scope 0 at test.rs:8:2: 8:2
    }

    bb2 (cleanup): {
        resume;                          // bb2[0]: scope 0 at test.rs:4:1: 8:2
    }
}
</pre></div>



<a name="165617845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165617845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165617845">(May 14 2019 at 12:33)</a>:</h4>
<p>If I do <code>let x = 1i32 as u32</code>, I get this:</p>
<div class="codehilite"><pre><span></span>        _1 = const 1i32 as u32 (Misc);   // bb0[1]: scope 0 at test.rs:5:13: 5:24
                                         // ty::Const
                                         // + ty: i32
                                         // + val: Scalar(Bits { size: 4, bits: 1 })
                                         // mir::Constant
                                         // + span: test.rs:5:13: 5:17
                                         // + ty: i32
                                         // + literal: Const { ty: i32, val: Scalar(Bits { size: 4, bits: 1 }) }
        StorageLive(_3);                 // bb0[2]: scope 2 at test.rs:6:10: 6:11
        _3 = _1;                         // bb0[3]: scope 2 at test.rs:6:10: 6:11
        _2 = const read(move _3) -&gt; bb1;
</pre></div>



<a name="165617926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165617926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165617926">(May 14 2019 at 12:35)</a>:</h4>
<p>ok, that is super odd. Because const prop works (<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=e3ce68eb4e44d21853e27f67ff989576" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=e3ce68eb4e44d21853e27f67ff989576">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=e3ce68eb4e44d21853e27f67ff989576</a>)</p>



<a name="165617946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165617946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165617946">(May 14 2019 at 12:35)</a>:</h4>
<p>did you build with debug assertions?</p>



<a name="165618002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618002">(May 14 2019 at 12:36)</a>:</h4>
<p>can you run with <code>RUSTC_LOG=rustc_mir::transforms::const_prop</code> and past the output somewhere?</p>



<a name="165618003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618003">(May 14 2019 at 12:36)</a>:</h4>
<p>I think so?</p>



<a name="165618008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618008">(May 14 2019 at 12:36)</a>:</h4>
<p>/me checking</p>



<a name="165618030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618030">(May 14 2019 at 12:36)</a>:</h4>
<div class="codehilite"><pre><span></span>TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: ConstProp starting for DefId(0/0:4 ~ test[317d]::main[0])
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: visit_statement: StorageLive(_1)
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: visit_statement: _1 = const 1i32 as u32 (Misc)
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: checking whether OpTy { op: Indirect(MemPlace { ptr: Ptr(Pointer { alloc_id: AllocId(0), offset: Size { raw: 0 }, tag: () }), align: Align { pow2: 2 }, meta: None }), layout: TyLayout { ty: u32, details: LayoutDetails { variants: Single { index: 0 }, fields: Union(0), abi: Scalar(Scalar { value: Int(I32, false), valid_range: 0..=4294967295 }), align: AbiAndPrefAlign { abi: Align { pow2: 2 }, pref: Align { pow2: 2 } }, size: Size { raw: 4 } } } } can be stored to _1
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: visit_constant: const 1i32
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: visit_statement: StorageLive(_3)
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: visit_statement: _3 = _1
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: visit_constant: const read
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: visit_statement: StorageDead(_3)
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: visit_statement: _0 = ()
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: visit_statement: StorageDead(_1)
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: ConstProp done for DefId(0/0:4 ~ test[317d]::main[0])
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: ConstProp starting for DefId(0/0:3 ~ test[317d]::read[0])
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: visit_statement: _0 = ()
TRACE 2019-05-14T12:36:33Z: rustc_mir::transform::const_prop: ConstProp done for DefId(0/0:3 ~ test[317d]::read[0])
</pre></div>



<a name="165618059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618059">(May 14 2019 at 12:37)</a>:</h4>
<p><code>debug-assertions = true</code> in my config.toml</p>



<a name="165618065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618065">(May 14 2019 at 12:37)</a>:</h4>
<p>oh, ignore my example! that was just a check</p>



<a name="165618066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618066">(May 14 2019 at 12:37)</a>:</h4>
<p>(I've got to run unfortunately)</p>



<a name="165618071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618071">(May 14 2019 at 12:37)</a>:</h4>
<p>what's the output on your code?</p>



<a name="165618079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618079">(May 14 2019 at 12:37)</a>:</h4>
<p>no prob! cu</p>



<a name="165618080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618080">(May 14 2019 at 12:37)</a>:</h4>
<p>The MIR output</p>



<a name="165618085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618085">(May 14 2019 at 12:37)</a>:</h4>
<p>?</p>



<a name="165618088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618088">(May 14 2019 at 12:37)</a>:</h4>
<p>No, that you already pasted</p>



<a name="165618089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618089">(May 14 2019 at 12:37)</a>:</h4>
<p>the trace</p>



<a name="165618138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618138">(May 14 2019 at 12:38)</a>:</h4>
<p>oh I'm stupid</p>



<a name="165618142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618142">(May 14 2019 at 12:38)</a>:</h4>
<p>ignore me, you posted everything</p>



<a name="165618147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618147">(May 14 2019 at 12:38)</a>:</h4>
<p>I'll look into it</p>



<a name="165618156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618156">(May 14 2019 at 12:38)</a>:</h4>
<p>Thanks <span class="user-mention" data-user-id="124288">@oli</span> and <span class="user-mention" data-user-id="119009">@eddyb</span>!</p>



<a name="165618157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165618157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165618157">(May 14 2019 at 12:38)</a>:</h4>
<p>ttyl</p>



<a name="165620936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165620936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165620936">(May 14 2019 at 13:16)</a>:</h4>
<p>So I have no clue why it isn't working. We'll need some more debug output. <a href="https://github.com/rust-lang/rust/blob/b92b1a76e175f396d7986177d0a2d5907bbba888/src/librustc_mir/transform/const_prop.rs#L547" target="_blank" title="https://github.com/rust-lang/rust/blob/b92b1a76e175f396d7986177d0a2d5907bbba888/src/librustc_mir/transform/const_prop.rs#L547">https://github.com/rust-lang/rust/blob/b92b1a76e175f396d7986177d0a2d5907bbba888/src/librustc_mir/transform/const_prop.rs#L547</a> and all other places setting <code>can_const_prop</code> to false should emit a <code>trace</code> with the <code>local</code> and the  reason</p>



<a name="165620982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165620982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165620982">(May 14 2019 at 13:17)</a>:</h4>
<p>So <a href="https://github.com/rust-lang/rust/blob/b92b1a76e175f396d7986177d0a2d5907bbba888/src/librustc_mir/transform/const_prop.rs#L527" target="_blank" title="https://github.com/rust-lang/rust/blob/b92b1a76e175f396d7986177d0a2d5907bbba888/src/librustc_mir/transform/const_prop.rs#L527">https://github.com/rust-lang/rust/blob/b92b1a76e175f396d7986177d0a2d5907bbba888/src/librustc_mir/transform/const_prop.rs#L527</a> too</p>



<a name="165621127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165621127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165621127">(May 14 2019 at 13:19)</a>:</h4>
<p>From your debug trace we hit the line before <a href="https://github.com/rust-lang/rust/blob/b92b1a76e175f396d7986177d0a2d5907bbba888/src/librustc_mir/transform/const_prop.rs#L588" target="_blank" title="https://github.com/rust-lang/rust/blob/b92b1a76e175f396d7986177d0a2d5907bbba888/src/librustc_mir/transform/const_prop.rs#L588">https://github.com/rust-lang/rust/blob/b92b1a76e175f396d7986177d0a2d5907bbba888/src/librustc_mir/transform/const_prop.rs#L588</a> but never the one after</p>



<a name="165621460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165621460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165621460">(May 14 2019 at 13:23)</a>:</h4>
<p>I can add some of those traces when I get back home tonight</p>



<a name="165621610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165621610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165621610">(May 14 2019 at 13:24)</a>:</h4>
<p>I've also seen some things like:</p>
<div class="codehilite"><pre><span></span>_2 = const 1i32;
_3 = move _2;
_4 = move _3;
</pre></div>


<p>defeat const prop.</p>



<a name="165621655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165621655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165621655">(May 14 2019 at 13:25)</a>:</h4>
<p>In some situations <code>_3</code> will be <code>can_const_prop = false</code></p>



<a name="165623162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165623162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165623162">(May 14 2019 at 13:42)</a>:</h4>
<p>if <code>_3</code> is written twice or a variable, then that is ok</p>



<a name="165623174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165623174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165623174">(May 14 2019 at 13:42)</a>:</h4>
<p>we are only const propagating temporaries atm</p>



<a name="165623290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165623290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165623290">(May 14 2019 at 13:44)</a>:</h4>
<p>hmm... variables that are only ever written once should be ok, too. I just have a feeling I tried that before and realized there's some odd way it doesn't work</p>



<a name="165623317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165623317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165623317">(May 14 2019 at 13:44)</a>:</h4>
<p>maybe <code>let x = if true { 42 } else { 43 };</code>? not sure</p>



<a name="165623527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165623527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165623527">(May 14 2019 at 13:47)</a>:</h4>
<p>I have a change locally that improves some of that which I think is ok but would have to be reviewed carefully.</p>



<a name="165623535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165623535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165623535">(May 14 2019 at 13:47)</a>:</h4>
<p>It doesn't break any tests though</p>



<a name="165623572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165623572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165623572">(May 14 2019 at 13:47)</a>:</h4>
<p>yea, we should do that in a separate PR</p>



<a name="165623628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165623628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165623628">(May 14 2019 at 13:48)</a>:</h4>
<p>same thing with this weird issue around casts</p>



<a name="165623930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165623930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165623930">(May 14 2019 at 13:51)</a>:</h4>
<p>Regarding the conversion method, should I move that from <code>const_eval.rs</code> to <code>eval_context.rs</code> where <code>InterpretCtx</code> lives? Or should I just make it <code>pub</code> so that it can be called from the conversion method?</p>



<a name="165624215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624215">(May 14 2019 at 13:55)</a>:</h4>
<p>I thought you created that method in <code>transforms/const_prop.rs</code>?</p>



<a name="165624236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624236">(May 14 2019 at 13:55)</a>:</h4>
<p>we may be talking about different conversion methods :D</p>



<a name="165624245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624245">(May 14 2019 at 13:55)</a>:</h4>
<p>Yeah, I think so lol</p>



<a name="165624257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624257">(May 14 2019 at 13:55)</a>:</h4>
<p>the ones in <code>const_eval.rs</code> are overkill</p>



<a name="165624264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624264">(May 14 2019 at 13:55)</a>:</h4>
<blockquote>
<p>Then you can add a call to <code>ecx.validate_operand(op, vec![], Some(&amp;mut RefTracking::new(op)), /*const_mode*/true)?;</code> to the conversion method.</p>
</blockquote>



<a name="165624268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624268">(May 14 2019 at 13:55)</a>:</h4>
<p>Did you mean a new conversion method?</p>



<a name="165624327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624327">(May 14 2019 at 13:56)</a>:</h4>
<p>Or the stuff I had added in <code>const_prop</code>?</p>



<a name="165624336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624336">(May 14 2019 at 13:56)</a>:</h4>
<p>I mean the <code>Scalar</code> -&gt; <code>ty::Const</code> you wrote in <code>const_prop</code></p>



<a name="165624349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624349">(May 14 2019 at 13:56)</a>:</h4>
<p>Ah ok</p>



<a name="165624365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624365">(May 14 2019 at 13:56)</a>:</h4>
<p>just validate the <code>OpTy</code> directly and do your conversion afterwards</p>



<a name="165624405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624405">(May 14 2019 at 13:57)</a>:</h4>
<p>Ok</p>



<a name="165624419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624419">(May 14 2019 at 13:57)</a>:</h4>
<p>I'm not sure what you meant here then: <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/const.20propagation/near/165613905" title="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/const.20propagation/near/165613905">https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/const.20propagation/near/165613905</a></p>



<a name="165624449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624449">(May 14 2019 at 13:57)</a>:</h4>
<p>that was one of the options. And not my favourite one ^^</p>



<a name="165624462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624462">(May 14 2019 at 13:57)</a>:</h4>
<p>Ok got it</p>



<a name="165624568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165624568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165624568">(May 14 2019 at 13:58)</a>:</h4>
<p>Calling <code>ecx.validate_operand</code> from the <code>Scalar</code> -&gt; <code>Const</code> function in <code>const_prop</code> should be easy enough then</p>



<a name="165707831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165707831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165707831">(May 15 2019 at 12:01)</a>:</h4>
<p>The reason why <code>const 1i32 as u32 (Misc);</code> doesn't get const-propagates is because it gets evaluated to an <code>Indirect</code> which <code>replace_with_const</code> doesn't handle:</p>
<div class="codehilite"><pre><span></span>TRACE 2019-05-15T11:58:05Z: rustc_mir::transform::const_prop: storing OpTy { op: Indirect(MemPlace { ptr: Ptr(Pointer { alloc_id: AllocId(0), offset: Size { raw: 0 }, tag: () }), align: Align { pow2: 2 }, meta: None }), layout: TyLayout { ty: u32, details: LayoutDetails { variants: Single { index: 0 }, fields: Union(0), abi: Scalar(Scalar { value: Int(I32, false), valid_range: 0..=4294967295 }), align: AbiAndPrefAlign { abi: Align { pow2: 2 }, pref: Align { pow2: 2 } }, size: Size { raw: 4 } } } } to _2
</pre></div>



<a name="165807034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165807034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165807034">(May 16 2019 at 12:59)</a>:</h4>
<p>ha! good catch</p>



<a name="165807058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165807058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165807058">(May 16 2019 at 12:59)</a>:</h4>
<p>I don't think anything speaks against handling <code>Indirect</code> by just creating a <code>ByRef</code> constant</p>



<a name="165807075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165807075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165807075">(May 16 2019 at 13:00)</a>:</h4>
<p>oh, maybe something does</p>



<a name="165807115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165807115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165807115">(May 16 2019 at 13:00)</a>:</h4>
<p>heh, this can be interesting</p>



<a name="165807137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165807137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165807137">(May 16 2019 at 13:00)</a>:</h4>
<p>I have written everything very defensively, so it should work, but I may have forgotten some places</p>



<a name="165807162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165807162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165807162">(May 16 2019 at 13:00)</a>:</h4>
<p>So if the <code>Indirect</code> doesn't point to the start of an allocation, we may run into trouble down the road</p>



<a name="165807217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165807217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165807217">(May 16 2019 at 13:01)</a>:</h4>
<p>I mean ideally we would not even create a duplicate of the allocation in llvm, but just create the const allocation and point to the sub-part of it</p>



<a name="165807236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165807236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165807236">(May 16 2019 at 13:02)</a>:</h4>
<p>oh, that may already work (the deduplication in llvm, not sure about the pointing at the right place)</p>



<a name="165809022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165809022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165809022">(May 16 2019 at 13:24)</a>:</h4>
<p>Ok. I can look into handling <code>Indirect</code> soon-ish.</p>



<a name="165809040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165809040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165809040">(May 16 2019 at 13:24)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/60597" target="_blank" title="https://github.com/rust-lang/rust/issues/60597">#60597</a> is ready for review again I believe.</p>



<a name="165816997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/165816997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#165816997">(May 16 2019 at 14:48)</a>:</h4>
<p>Thanks oli!</p>



<a name="166039747"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166039747" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166039747">(May 19 2019 at 20:53)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> I'm not sure what RFC <a href="https://github.com/rust-lang/rust/pull/60745#issuecomment-493735645" target="_blank" title="https://github.com/rust-lang/rust/pull/60745#issuecomment-493735645">your comment</a> is referring to but I think changing the <code>SwitchInt</code> test to call a function other than <code>std::process:exit()</code> should fix the build error on wasm.</p>



<a name="166039804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166039804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166039804">(May 19 2019 at 20:54)</a>:</h4>
<p>lolwat, sorry. I commented on the wrong PR</p>



<a name="166039833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166039833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166039833">(May 19 2019 at 20:55)</a>:</h4>
<p>sorry, removed the comment and commented on the correct PR</p>



<a name="166039835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166039835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166039835">(May 19 2019 at 20:55)</a>:</h4>
<p>E-too-many-tabs</p>



<a name="166039991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166039991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166039991">(May 19 2019 at 20:59)</a>:</h4>
<p>Haha I figured :)</p>



<a name="166040624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166040624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166040624">(May 19 2019 at 21:14)</a>:</h4>
<p>You should const prop into <code>Yield</code> terminators too. Just repeating here since github likes to hide comments</p>



<a name="166040820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166040820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166040820">(May 19 2019 at 21:19)</a>:</h4>
<p>hmm curious. I would have assumed <code>Yield</code> to do the same thing that <code>return</code> does and just write to a magic local before the terminator</p>



<a name="166040962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166040962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166040962">(May 19 2019 at 21:23)</a>:</h4>
<p>Nah, it's more source code like. Not sure why we use Pascal style returns in MIR =P</p>



<a name="166042719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166042719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166042719">(May 19 2019 at 22:10)</a>:</h4>
<p>because it allows some optimizations like filling in the return value element wise instead of creating a local, filling that in and copying all over at once in the return</p>



<a name="166042725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166042725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166042725">(May 19 2019 at 22:10)</a>:</h4>
<p>the same should go for yields</p>



<a name="166043225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166043225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166043225">(May 19 2019 at 22:24)</a>:</h4>
<p>It would probably optimize to the same code post-transformation anyway</p>



<a name="166053587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166053587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166053587">(May 20 2019 at 03:26)</a>:</h4>
<p><span class="user-mention" data-user-id="116466">@Zoxc</span> Do you have an example which generates <code>Yield</code>s? Whenever I try it, I just get MIR that's already had the <code>Yield</code> lowered: <a href="https://gist.github.com/wesleywiser/8af2517dfa5254cd226b8ae6631266e7" target="_blank" title="https://gist.github.com/wesleywiser/8af2517dfa5254cd226b8ae6631266e7">https://gist.github.com/wesleywiser/8af2517dfa5254cd226b8ae6631266e7</a></p>



<a name="166053671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166053671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166053671">(May 20 2019 at 03:29)</a>:</h4>
<p>You'll have to run <code>ConstProp</code> before the transform</p>



<a name="166053728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166053728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166053728">(May 20 2019 at 03:30)</a>:</h4>
<p>Oh, ok. I see</p>



<a name="166053744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166053744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166053744">(May 20 2019 at 03:31)</a>:</h4>
<p>I think it was moved up due to an issue with one of the later passes</p>



<a name="166053796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166053796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166053796">(May 20 2019 at 03:32)</a>:</h4>
<p>The commit which added the Deaggregator moved it</p>



<a name="166068447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166068447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166068447">(May 20 2019 at 09:02)</a>:</h4>
<p>hmm... we'd have to run <code>ConstProp</code> multiple times then or move const qualif also before the generator lowering</p>



<a name="166068454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166068454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166068454">(May 20 2019 at 09:02)</a>:</h4>
<p>because <code>ConstProp</code> can't run before <code>const_qualif</code></p>



<a name="166068470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166068470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166068470">(May 20 2019 at 09:03)</a>:</h4>
<p><code>const_qualif</code> is a guaranteed optimization (wrt promotion)</p>



<a name="166068489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166068489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166068489">(May 20 2019 at 09:03)</a>:</h4>
<p>const prop may mess that up</p>



<a name="166125585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166125585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166125585">(May 20 2019 at 22:36)</a>:</h4>
<p>Have you tested whether always running const prop would help compile times? i.e. also for debug?</p>



<a name="166126255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166126255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166126255">(May 20 2019 at 22:46)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> Yes: <a href="https://perf.rust-lang.org/compare.html?start=5f1924c9922c640108d2225d6b68e69e589b94ae&amp;end=7f66c41c4e89b51c8b68f7019cad02c0f46cd1e1" target="_blank" title="https://perf.rust-lang.org/compare.html?start=5f1924c9922c640108d2225d6b68e69e589b94ae&amp;end=7f66c41c4e89b51c8b68f7019cad02c0f46cd1e1">https://perf.rust-lang.org/compare.html?start=5f1924c9922c640108d2225d6b68e69e589b94ae&amp;end=7f66c41c4e89b51c8b68f7019cad02c0f46cd1e1</a></p>



<a name="166126277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166126277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166126277">(May 20 2019 at 22:47)</a>:</h4>
<p>cool</p>



<a name="166126626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166126626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166126626">(May 20 2019 at 22:53)</a>:</h4>
<p>Why does it help check builds?</p>



<a name="166126873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20propagation/near/166126873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20propagation.html#166126873">(May 20 2019 at 22:58)</a>:</h4>
<p>I assume it's because CTFE tests run less code?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>